package com.springboot.messagewall.mapper;


import com.springboot.messagewall.model.MessageInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-03-23
 * Time: 13:51
 */
@Mapper
public interface MessageInfoMapper {
    // 插入留言 -> insert
    @Insert("insert into message_info (`from`, `to`, message) values " +
            "(#{from}, #{to}, #{message})")
    Integer insertMessageInfo(MessageInfo messageInfo);

    // 获取所有留言信息 -> select
    // 查询时，查找并未被删除的
    @Select("select * from message_info where delete_flag = 0")
    List<MessageInfo> selectAllMessageInfo();

    @Update("update message_info set delete_flag = 1 " +
            "where `from` = #{from} and `to` = #{to} and message = #{message}")
    Integer deleteMessage(MessageInfo messageInfo);
}
